package xyz.mumu233.muxinnetty.utils;

import xyz.mumu233.muxinnetty.pojo.Users;

import javax.persistence.Column;
import java.lang.reflect.Field;

public class ColumnUtil {
    public static void main(String[] args) {
        String str=getColumnValue(Users.class,"faceImage");
            System.out.println(str);
    }
    public static String getColumnValue(Class classz,String name) {
        Field[] fields=classz.getDeclaredFields();
        Field field;
        String value = null;
        for (int i = 0; i <fields.length ; i++) {
            fields[i].setAccessible(true);
        }
        for(int i = 1;i<fields.length ; i++){
            try {
                field=classz.getDeclaredField(fields[i].getName());
                Column column=field.getAnnotation(Column.class); //获取指定类型注解
                if (name.equals(fields[i].getName())){
                    if(column!=null){
                        return column.name();
                    }else{
                        return fields[i].getName();
                    }
                }

            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            }
        }
        return value;
    }
}